package xyf.p10.dp;

import java.util.List;

/**
 * ClassName: P0139_WordBreak
 * Description:
 * Author: xyf
 * Date: 9/9/22 10:29 AM
 * Version: 1.0
 **/
public class P0139_WordBreak
{
    public boolean wordBreak(String s, List<String> wordDict)
    {
        boolean[] dp = new boolean[s.length() + 1];
        dp[0] = true;

        for (int i = 1; i < s.length() + 1; i++)
        {
            for (int j = 0; j < i; j++)
            {
                if (dp[j] && wordDict.contains(s.substring(j, i)))
                {
                    dp[i] = true;
                }
            }
        }

        return dp[s.length()];
    }
}